from PIL import Image
import numpy as np
import os
if __name__ == "__main__":
    imagePath = "/Users/joker/Workplace/health/health/Assets.xcassets/images/navi_back.imageset/navi_back@3x.png"
    image = Image.open(imagePath)
#     image.show()
    img_arr = np.array(image)
    shape = img_arr.shape
    height = shape[0]
    width = shape[1]
    dst = np.zeros((height,width,4))
    for h in range(0,height):
        for w in range (0,width):
            print(img_arr[h,w].size)
            if img_arr[h,w].size == 2:
                (v,a) = img_arr[h,w]
                if v > 0:
                    dst[h,w] = (0,0,0,a)
                else:
                    dst[h,w] = (v,v,v,a)
            else:
                (b,g,r,a) = img_arr[h,w]
                if r > 0:
                    dst[h,w] = (0,0,0,a)
                else:
                    dst[h,w] = (b,g,r,a)
    img2 = Image.fromarray(np.uint8(dst))
    img2.save(f"/Users/joker/Desktop/3x/navi_back@3x.png","png")
    img2.thumbnail((width * 2 / 3,height * 2 / 3))
    img2.save(f"/Users/joker/Desktop/3x/navi_back@2x.png","png")